package fr.afcepf.atod18.ws.currencies.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Component;

@Component
public class CurrencyDAO implements ICurrencyDAO {
    @PersistenceContext
    EntityManager em;

    @SuppressWarnings("unchecked")
    public List<CurrencyPersistence> getAll() {
        Query qu = em.createQuery("SELECT c FROM CurrencyPersistence c");
        return qu.getResultList();
    }
    
    @SuppressWarnings("unchecked")
    public List<CurrencyPersistence> getCurrencyByName( String paramName ) {
        Query qu = em.createQuery("SELECT c FROM CurrencyPersistence c WHERE c.name LIKE :name");
        qu.setParameter("name", paramName);
        return qu.getResultList();
    }
}
